import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:magma/heartbeat/helpers/magma_constant.dart';
import 'package:qlevar_router/qlevar_router.dart';
import '../helpers/magma_color.dart';
import '../helpers/magma_text_style.dart';
import '../helpers/magma_router.dart';

/// 需要登录的弹窗组件
class LoginRequiredDialog extends StatelessWidget {
  final String? title;
  final String? message;
  final String? confirmText;
  final String? cancelText;

  const LoginRequiredDialog({
    super.key,
    this.title,
    this.message,
    this.confirmText,
    this.cancelText,
  });

  /// 显示登录弹窗
  static Future<void> show(
    BuildContext context, {
    String? title,
    String? message,
    String? confirmText,
    String? cancelText,
  }) {
    return showDialog<void>(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return LoginRequiredDialog(
          title: title,
          message: message,
          confirmText: confirmText,
          cancelText: cancelText,
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: MagmaColor.black,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(16.r),
        side: BorderSide(color: MagmaColor.green, width: 1.w),
      ),
      child: Padding(
        padding: EdgeInsets.all(24.w),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // 图标
            Container(
              width: 64.w,
              height: 64.w,
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: AssetImage(MagmaConstant.logo),
                  fit: BoxFit.cover,
                ),
                shape: BoxShape.circle,
              ),
            ),
            SizedBox(height: 16.h),

            // 标题
            Text(title ?? 'Authentication Required').blackHanSans(
              fontSize: 20.sp,
              color: MagmaColor.white,
              fontWeight: FontWeight.w600,
            ),
            SizedBox(height: 8.h),

            // 描述
            Text(
              message ?? 'Please log in to continue using this feature.',
              textAlign: TextAlign.center,
            ).inter(
              fontSize: 14.sp,
              color: MagmaColor.white.withOpacity(0.7),
              fontWeight: FontWeight.w400,
            ),
            SizedBox(height: 24.h),

            // 按钮
            Row(
              children: [
                Expanded(
                  child: TextButton(
                    onPressed: () => Navigator.of(context).pop(),
                    style: TextButton.styleFrom(
                      padding: EdgeInsets.symmetric(vertical: 12.h),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(8.r),
                        side: BorderSide(
                          color: MagmaColor.white.withOpacity(0.3),
                        ),
                      ),
                    ),
                    child: Text(cancelText ?? 'Cancel').inter(
                      fontSize: 14.sp,
                      color: MagmaColor.white,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
                SizedBox(width: 12.w),
                Expanded(
                  child: ElevatedButton(
                    onPressed: () {
                      Navigator.of(context).pop();
                      QR.to(MagmaRouter.loginPath);
                    },
                    style: ElevatedButton.styleFrom(
                      backgroundColor: MagmaColor.purple,
                      padding: EdgeInsets.symmetric(vertical: 12.h),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(8.r),
                      ),
                    ),
                    child: Text(confirmText ?? 'Login').inter(
                      fontSize: 14.sp,
                      color: MagmaColor.white,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
